{% extends "base.html" %}
{% block title %}SDK测包管理{% endblock %}
{% block content-header %}SDK日志测试管理{% endblock %}
{% block content-header-description %}{% endblock %}
{% block breadcrumb-app %}<a href="/pkg">SDK日志测试管理</a>{% endblock %}
{% block custom_content %}
    <style>
        /* 晕状 */

        hr.style-line {
            margin-top: 40px;
            height: 0px;
            border-style: solid;
            border-color: black;
            border-width: 1px 0 0 0;
            border-radius: 20px;
        }

        hr.style-line:before {
            display: block;
            content: "";
            height: 30px;
            margin-top: -31px;
            border-style: solid;
            border-color: black;
            border-width: 0 0 1px 0;
            border-radius: 20px;
        }

        td.ext {
            margin-top: 6px;
            background-color: #d9edf7;
        }

        .case_basic label {
            padding-top: 0px;
        }

        @media (min-width: 992px) {
            .modal-lg {
                width: 1200px;
            }
        }


    </style>
    <!-- 信息删除确认 模态框 -->
    <div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-label="Close">
                        <span aria-hidden="true">×</span></button>
                    <h4 class="modal-title">操作确认</h4>
                </div>
                <div class="modal-body">
                    确认删除该记录吗？
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                    <a class="btn btn-danger btn-ok">删除记录</a>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div><!-- /.modal -->


    <!-- 测试说明 模态框 -->
    <div class="modal fade" id="stepModal" tabindex="-1" role="dialog"
         aria-labelledby="stepModal">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="stepModal">Log
                        Detail:Case_id=</h4>
                </div>
                <div class="modal-body request_log">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">
                        关闭
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- 邮件确认 模态框 -->
    <div class="modal fade" id="emailModal" tabindex="-1" role="dialog"
         aria-labelledby="emailModal">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="emailModal"></h4>
                </div>
                <div class="modal-body request_log form-horizontal" id="report">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">
                        取消
                    </button>
                    <button type="button" class="btn btn-default cp"
                            href="javascript:"
                            data-clipboard-target="#report">复制
                    </button>
                </div>
            </div>
        </div>
    </div>
    {% if user.is_authenticated %}
{#        {% if user.userprofile.settings %}#}
{#            <script>#}
{#                var settings = {{ user.userprofile.settings|safe|default:"11" }};#}
{#                //console.log(settings.sidebar_collapse);#}
{#                if (settings.sidebar_collapse == "true") {#}
{#                    document.getElementsByTagName("body")[0].setAttribute("class", "skin-blue sidebar-mini sidebar-collapse");#}
{#                } else {#}
{#                    document.getElementsByTagName("body")[0].setAttribute("class", "skin-blue sidebar-mini");#}
{#                }#}
{#            </script>#}
{#        {% endif %}#}
    {% endif %}
{% endblock %}

{% block custom-js-code %}

    <script>
        $.ajaxSetup({
            data: {csrfmiddlewaretoken: '{{ csrf_token }}'},
        });

    </script>

    <!-- 粘贴板复制 -->
    <script type='text/javascript'
            src="/static/custom/clipboard.min.js"></script>
    <script type='text/javascript'>
        var clipboard = new Clipboard('.cp');
        clipboard.on('success', function (e) {
            //console.info('Action:', e.action);
            //console.info('Text:', e.text);
            //console.info('Trigger:', e.trigger);
            alert("复制成功！");
            e.clearSelection();
        });
        clipboard.on('error', function (e) {
            alert("复制失败！");
            console.error('Action:', e.action);
            console.error('Trigger:', e.trigger);
        });
    </script>

    <!-- CK 编辑器 -->
    <script src="/static/plugins/ckeditor/ckeditor.js"></script>
    <script>
        var game_ext_editor;
        game_ext = $('#game_ext');
        game_extHTML = game_ext.innerHTML;
        if (game_ext.length) {
            CKEDITOR.replace('game_ext', {
                extraPlugins: 'autogrow',
                autoGrow_maxHeight: 3000,
                autoGrow_bottomSpace: 50,
                removePlugins: 'resize',
                uiColor: '#CCEAEE',
                skin: 'bootstrapck'
            });

            CKEDITOR.on('instanceReady', function (ev) {
                game_ext_editor = ev.editor;
                game_ext_editor.setReadOnly(true);

                // Show this "on" button.
                $('#edit').css('display', '')

                // Event fired when the readOnly property changes.
                game_ext_editor.on('readOnly', function () {
                    document.getElementById('reset').style.display = this.readOnly ? 'none' : '';
                    document.getElementById('save').style.display = this.readOnly ? 'none' : '';
                    document.getElementById('edit').style.display = this.readOnly ? '' : 'none';
                });
            });
        }


        // The instanceReady event is fired when an instance of CKEditor has finished
        // its initialization.


        function toggleReadOnly(isReadOnly) {
            game_ext_editor.setReadOnly(isReadOnly);
            if (game_ext_editor && game_ext_editor.checkDirty()) {
                reset.style.display = 'inline';
            }

        }

        function resetContent() {
            toggleReadOnly();
            reset.style.display = 'none';
            game_ext_editor.setData(game_extHTML);
        }

    </script>

    <script>
        $(document).ready(function () {
            <!-- 初始化dataTable -->
            $('.dt').dataTable({
                "scrollY": "450px",
                "scrollCollapse": "true",
                "paging": "false",
                "order": [[0, 'desc']]
            });
            <!-- 下载二维码 -->
            $("#btn_qrcode").mouseover(function gen_qrcode() {
                var path = $("#apk").val();
                if (path) {
                    var target = path.replace("D:\\pkg", 'http://10.1.102.75:8001');
                    var str = toUtf8(target);
                    jQuery('#qrcodeCanvas').qrcode({
                        text: str
                    });
                }

            });
            $("#btn_qrcode").mouseleave(function clear_qrcode() {
                $("#qrcodeCanvas").empty();
            });
            function toUtf8(str) {
                var out, i, len, c;
                out = "";
                len = str.length;
                for (i = 0; i < len; i++) {
                    c = str.charCodeAt(i);
                    if ((c >= 0x0001) && (c <= 0x007F)) {
                        out += str.charAt(i);
                    } else if (c > 0x07FF) {
                        out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
                        out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
                        out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
                    } else {
                        out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
                        out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
                    }
                }
                return out;
            }


            <!-- 点击新增按钮时 socket 连接-->
            $("#add_case").click(
                function () {
                    var client_id = $("#client").val();
                    // socket 日志处理函数
                    socket_handler(client_id);
                }
            );
            <!-- 点击修改按钮时 socket 连接-->
            $("#update_case").click(
                function () {
                    var client_id = $("#client").val();
                    // socket 日志处理函数
                    socket_handler(client_id);
                }
            );
        });
    </script>

    <script>
        var API_LOOP;
        var CASE_TIME;

        //打开redis持久数据查询窗口
        function search_redis() {
            var client_id = $('#client').val();
            var d = new Date();
            var vYear = d.getFullYear();
            var vMon = d.getMonth() + 1;
            if (parseInt(vMon) < 10) {
                vMon = "0" + vMon;
            }
            var vDay = d.getDate();
            if (parseInt(vDay) < 10) {
                vDay = "0" + vDay;
            }
            url = "{% url 'sdk_log' %}" + "?gameId=" + client_id + "&date=" + vYear + vMon + vDay;
            window.open(url);
        }

        <!-- 保存游戏扩展信息 -->
        function saveData() {
            toggleReadOnly();
            reset.style.display = 'none';
            var client = $('#client').val();
            if (client && game_ext_editor) {
                var ext = game_ext_editor.getData();
                $.ajax({
                    url: '{% url "update_game_ext" %}',
                    type: 'POST',
                    data: {"client_id": client, "game_ext": ext},
                    dataType: 'json',
                    success: function (data) {
                        console.log("update_game_ext:", data);
                        {#                        $('#save_result').html(data.msg);#}
                    }
                });
            }
        }

        <!-- 显示历史用例数据 -->
        function show_logs() {
            var client_id = $('#client').val();
            if (client_id) {
                var url = "{% url 'pkg_jm' '001' '/logs' %}";
                url = url.replace('001', client_id);
                window.open(url);
            }
        }
        <!-- 删除当前记录用例数据 -->
        function case_del() {
            var log_id = $('#log_id').val();
            var client_id = $('#client').val();
            if (log_id) {
                var url = '{% url "del_log"  001 %}';
                url = url.replace(001, log_id);
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: {},
                    dataType: 'json',
                    success: function (data) {
                        window.location.href = "/pkg";
                    }
                });

            } else {
                alert("log_id 为空，请检查！");
            }
        }


        <!-- 新增用例 编辑状态-->
        function make_add() {
            $('#log_id').val('');
            $('#game_detail').removeAttr('disabled');
            $('#test_ext').removeAttr('disabled');
            $('#apk').removeAttr('disabled');
            $('#apk').selectpicker('refresh');
            $("select").val('');
            $(".case_info").val('');
            //$(".auto").val('');
            // 遍历ext输入框备注栏，如果备注栏内容以"["开头，以"]"结束，则清空输入框内容
            $(".ext").each(function () {
                $(this).val($(this).val().replace(/(\[.*?\])/g, ""));
            });

            // 用例时间
            CASE_TIME = Math.round(new Date().getTime() / 1000);
            //console.log("CASE_TIME:"+CASE_TIME);
            // 日志开启
            var client_id = $('#client').val();
            log_handdle(client_id, true);
        }

        <!-- 修改用例，编辑状态 -->
        function make_edit() {
            $('#game_detail').removeAttr('disabled');
            $('#test_ext').removeAttr('disabled');
            $('#apk').removeAttr('disabled');
            $('#apk').selectpicker('refresh');
            $("input").attr("disabled", false);
            $("select").attr("disabled", false);
            $("textarea").attr("disabled", false);
            // 用例时间
            CASE_TIME = Math.round(new Date().getTime() / 1000);
            // 日志开启
            var client_id = $('#client').val();
            log_handdle(client_id, true);
        }

        <!-- 根据下拉选项recharge onchange的值来填充获取订单号日志，充值到游戏日志用例 -->
        function change_recharge() {
            var recharge = $('#recharge').val();
            $('.recharge_switch').hide();
            if (recharge == "0") { // 非充值包
                // 获取订单号，充值到游戏用例 填充“暂不接入”
                $('#pay_num_dl').val(2);
                $('#recharge_dl').val(2);
                $('#recharge_ly').val(2);
                // 充值开关用例，填充 “忽略”
                $('#recharge_switch_dl').val(3);
                $('#recharge_switch_ext').val("不适用充值开关");
            } else if (recharge == "1") {  // 充值包
                $('#pay_num_dl').val("");
                $('#recharge_dl').val("");
                $('#recharge_ly').val("");
                // 充值开关用例，填充 “忽略”
                $('#recharge_switch_dl').val(3);
                $('#recharge_switch_ext').val("不适用充值开关");
            } else if (recharge == "2") {
                $('.recharge_switch').show();
                $('#recharge_switch_dl').val("");
                $('#recharge_switch_ext').val("");
            }

        }

        <!-- 拉取sdk 服务端api日志 report -->
        function show_api_report(client_id) {
            var device_id = $('#device_id').val();
            var recharge;
            var p1 = $('#recharge').children('option:selected').val();
            if (p1 != "0") {
                recharge = "true";
            }
            var regist_dl_result = $('#regist_dl').val();
            var recharge_dl_result = $('#recharge_dl').val();
            var recharge_ly_result = $('#recharge_ly').val();
            var after_login_ly_result = $('#after_login_ly').val();
            var after_login_dl_result = $('#after_login_dl').val();
            var paynum_result = $('#pay_num_dl').val();
            var yd_flag = $('#project_id').is(":hidden");
            if (client_id && device_id) {
                if ($("#game_detail").attr("disabled") != "disabled") {
                    if (yd_flag) {// 非源点日志,传统日志
                        $.ajax({
                            url: "{% url 'sdk_api_report' %}",
                            type: "GET",
                            data: {
                                'gameId': client_id,
                                'device_id': device_id,
                                'recharge': recharge,
                                'regist_dl_result': regist_dl_result,
                                'after_login_dl_result': after_login_dl_result,
                                'after_login_ly_result': after_login_ly_result,
                                'recharge_dl_result': recharge_dl_result,
                                'recharge_ly_result': recharge_ly_result,
                                'paynum_result': paynum_result,
                                'case_time': CASE_TIME
                            },
                            dataType: 'json',
                            success: function (data) {
                                // 大陆sy 注册日志
                                if (data.sy_report.reg) {
                                    $('#regist_dl').val(1);
                                    $('#regist_ext').val($('#regist_ext').val().replace(/\[.*?\]/g, "") + "[uid=" + data.sy_report.reg[0].uid + "]");
                                }
                                // 大陆sy 登录完成日志
                                if (data.sy_report.login) {
                                    $('#after_login_dl').val(1);
                                    $('#after_login_ext').val($('#after_login_ext').val().replace(/\[.*?\]/g, "") + "[uid=" + data.sy_report.login[0].uid + "]");

                                }
                                // 大陆联运ly 登录完成日志
                                if (data.udp_report.login) {
                                    $('#after_login_ly').val(1);
                                    $("select#after_login_ly").find("option[value='1']").attr("selected", true);
                                }
                                // 大陆sy 获取订单号日志
                                if (data.sy_report.paynum) {
                                    $('#pay_num_dl').val(1);
                                    $('#pay_num_ext').val($('#pay_num_ext').val().replace(/\[.*?\]/g, "") + "[pay_num=" + data.sy_report.paynum[0]['pay_num'] + ";uid=" + data.sy_report.paynum[0].uid + "]")

                                }
                                // 大陆sy 充值到游戏日志
                                if (data.sy_report.recharge) {
                                    $('#recharge_dl').val(1);
                                    $('#recharge_ext').val($('#recharge_ext').val().replace(/\[.*?\]/g, "") + "[pay_num=" + data.sy_report.recharge[0]['pay_num'] + ";uid=" + data.sy_report.recharge[0].uid + "]")

                                }
                                // 大陆联运ly 充值到游戏日志
                                if (data.udp_report.recharge) {
                                    $('#recharge_ly').val(1);
                                }
                            }

                        });
                    } else { // 源点日志
                        if ($('#recharge_yd').val() == "") {
                            $.ajax({
                                url: "{% url 'get_yd_api' %}",
                                type: "GET",
                                data: {
                                    "projectid": $('#project_id').val(),
                                    "time": CASE_TIME,
                                    "select": {
                                        "gameid": client_id,
                                        "did": device_id
                                    },
                                },
                                dataType: 'json',
                                success: function (data) {
                                    if (data.length > 0) {
                                        console.log("源点充值日志：", data.data[0]);
                                        $('#recharge_yd').val(1);
                                        $('#recharge_ext').val($('#recharge_ext').val().replace(/\[.*?\]/g, "") + "[pay_num=" + data.data[0]["paynum"] + ";uid=" + data.data[0]["uid"] + "]")
                                    } else {
                                        //console.log("源点充值日志未产生：",data.data);
                                    }

                                }

                            })
                        }

                    }


                }
            }
        }

        <!-- 获取游戏详细信息-->
        var prev_client_id;
        function get_game_info(e) {
            var client_id = $(e).val();
            if (prev_client_id) {
                // 日志停止
                log_handdle(prev_client_id, false);
            }
            // 取消game_detail 中所有的下拉选择selected，重新赋值，避免一个select中多个option被选中
            $("#game_detail select option:selected").removeAttr("selected");
            if (client_id) {
                var url = '{% url "get_game_info"  001 %}';
                url = url.replace(001, client_id);
                $.ajax({
                    url: url,
                    type: 'GET',
                    data: {},
                    dataType: 'json',
                    success: function (data) {
                        prev_client_id = data.client_id;
                        $("#case_content").css('display', 'block');
                        //console.log("get_game_info:", data);
                        // 源点接入判断
                        if (data.yd_flag) { //源点包，显示源点用例
                            $('.common_type').hide();
                            $('.yd_type').show();
                            $('#sdk_info').attr('rowspan', 2);
                            $('#client_log').attr('rowspan', 7);
                            $('#server_log').attr('rowspan', 2);
                            $('.qita').attr('colspan', 1);
                            $('#client_log_ios').attr('rowspan', 7);
                            $('#server_log_ios').attr('rowspan', 2);
                            $('.qita_ios').attr('colspan', 1);
                            $('select#pt_type').val("sy");
                            $('.sy').show();
                        } else { // 普通包，显示普通包用例
                            $('.common_type').show();
                            $('.yd_type').hide();
                            $('#sdk_info').attr('rowspan', 3);
                            $('#client_log').attr('rowspan', 8);
                            $('#server_log').attr('rowspan', 5);
                            $('.qita').attr('colspan', 2);
                            $('#client_log_ios').attr('rowspan', 7);
                            $('#server_log_ios').attr('rowspan', 4);
                            $('.qita_ios').attr('colspan', 1);
                        }
                        $('#game_detail').attr('disabled', 'disabled');
                        $('#test_ext').attr('disabled', 'disabled');
                        $('#client').val(data.client_id);
                        $('#game_type').val(data.game_type);
                        $('#game_name').val(data.name);
                        if (game_ext_editor) {
                            game_extHTML = data.game_ext;
                            game_ext_editor.setData(game_extHTML);
                        }

                        var case_info = "";
                        if (data.case_log) {
                            $('#log_id').val(data.case_log.log_id);
                            $('#appver').val(data.case_log.appver);
                            $('#sy_sdk').val(data.case_log.sy_sdk);
                            $('#fn_sdk').val(data.case_log.fn_sdk);
                            $('#vcode').val(data.case_log.vcode);
                            $("select#recharge").val(data.case_log.recharge);
                            $('#package').val(data.case_log.package);
                            $('#md5').val(data.case_log.md5);
                            $('#suid').val(data.case_log.suid);
                            $('#device_id').val(data.case_log.device_id);
                            $('#plat_channel').val(data.case_log.plat_channel);
                            $('#sy_channel').val(data.case_log.sy_channel);
                            $('#modify_date').val(data.case_log.creator + "|" + data.case_log.modify_date);
                            $("select#pt_type").val(data.case_log.pt_type);
                            $("select#result").val(data.case_log.result);

                            if (data.case_log.recharge == "0" || data.case_log.recharge == "1") {
                                $('.recharge_switch').hide();
                            } else {
                                $('.recharge_switch').show();
                            }
                            if (data.case_log.pt_type == "jm") {
                                $('.sy').hide();
                            } else {
                                $('.sy').show();
                            }

                            $('#test_ext').val(data.case_log.test_ext);

                            case_info = data.case_log.case_info;
                            if (case_info.ext) {
                                $('#project_id').val(case_info.ext.project_id);
                            }
                            $.each(case_info, function (name, value) {
                                $.each(value, function (name2, value2) {

                                    if (name2 == "ext") {
                                        var p_id = "#" + name + "_" + name2;
                                        $(p_id).val(value2);
                                    } else if (name2 == "yd_ext") {
                                        var p_id = "#" + name + "_" + name2;
                                        $(p_id).val(value2);
                                    } else {
                                        var select_id = "select#" + name + "_" + name2;
                                        if (value2) {
                                            $(select_id).val(value2);
                                        }
                                    }
                                })
                            });
                        } else {
                            $('.edit_log').val("");
                            $('select').val("");
                        }
                        // 设置新玩家模式显示状态
                        if (data.new_user_setting == "on") {
                            $('#new_user_setting').val("off");
                            $('#new_user').text("新玩家模式on");
                        } else {
                            $('#new_user_setting').val("on");
                            $('#new_user').text("新玩家模式off");
                        }

                    }
                });
            }


        }

        <!-- 获取apk详细信息-->
        function get_apk_info() {
            var apk_path = $('#apk option:selected').val();
            $.ajax({
                url: "{% url 'apk_info' %}",
                type: "GET",
                data: {'apk_path': apk_path},
                dataType: 'json',
                success: function (data) {
                    $('#md5').val(data.apk_md5);
                    $('#plat_channel').val(data.apk_info.PLAT_CHANNEL);
                    $('#sy_channel').val(data.apk_info.channelId);
                    $('#package').val(data.apk_info.package);
                    var error_flag = false;
                    var error_msg = "";
                    $.getJSON('{% url "last_version" %}', {"game_id": $('#client').val()}, function (vdata) {
                        if (parseInt(data.apk_info.versionCode) <= parseInt(vdata.vcode)) {
                            //versionCode 不正确
                            error_flag = true;
                            console.log("versionCode 不正确!");
                        }
                        if (versionCompare(vdata.appver, data.apk_info.versionName)) {
                            //versionName 不正确
                            error_flag = true;
                            console.log("versionName 不正确!");
                        }
                        console.log("当前版本versionName为:" + data.apk_info.versionName + " | 上一版本versionName为:" + vdata.appver);
                        console.log("当前版本versionCode为:" + data.apk_info.versionCode + " | 上一版本versionCode为:" + vdata.vcode);
                        if (error_flag) {
                            error_msg = "当前版本：versionName=" + data.apk_info.versionName + "，versionCode=" + data.apk_info.versionCode + "\n上一版本：versionName=" + vdata.appver + "，versionCode=" + vdata.vcode;
                            error_msg += "\n请仔细核查！\n[对比条件:以一天前的测试记录为对比]";
                            alert(error_msg);
                        }
                    });
                    // 填充appversion版本号
                    $('#appver').val(data.apk_info.versionName);
                    // 填充versionCode
                    $('#vcode').val(data.apk_info.versionCode);
                    console.log("apk_info:", data);
                }
            });

        }

        <!-- 保存用例执行信息 -->
        function case_save() {
            var client_id = $('#client').val();
            var result = $('#result').val();
            if (client_id) {
                var url = '{% url "add_game_log"  001 %}';
                url = url.replace(001, client_id);
                if (result == "") {
                    alert("请先填写测试结果再保存！");
                } else {
                    $.ajax({
                        url: url,
                        type: 'POST',
                        data: {
                            "log_id": $('#log_id').val(),
                            "appver": $('#appver').val(),
                            "pt_type": $('#pt_type').val(),
                            "sy_sdk": $('#sy_sdk').val(),
                            "fn_sdk": $('#fn_sdk').val(),
                            "vcode": $('#vcode').val(),
                            "recharge": $('#recharge').val(),
                            "package": $('#package').val(),
                            "md5": $('#md5').val(),
                            "result": $('#result').val(),
                            "suid": $('#suid').val(),
                            "device_id": $('#device_id').val(),
                            "plat_channel": $('#plat_channel').val(),
                            "sy_channel": $('#sy_channel').val(),
                            "project_id": $('#project_id').val(),

                            "open_game_dl": $('#open_game_dl').val(),
                            "open_game_ly": $('#open_game_ly').val(),
                            "open_game_yd": $('#open_game_yd').val(),
                            "open_game_ext": $('#open_game_ext').val(),

                            "before_login_dl": $('#before_login_dl').val(),
                            "before_login_ly": $('#before_login_ly').val(),
                            "before_login_ext": $('#before_login_ext').val(),

                            "regist_dl": $('#regist_dl').val(),
                            "regist_ext": $('#regist_ext').val(),
                            "regist_yd": $('#regist_yd').val(),
                            "regist_yd_ext": $('#regist_yd_ext').val(),

                            "login_yd": $('#login_yd').val(),
                            "login_ext": $('#login_ext').val(),

                            "after_login_dl": $('#after_login_dl').val(),
                            "after_login_ly": $('#after_login_ly').val(),
                            "after_login_ext": $('#after_login_ext').val(),

                            "select_server_dl": $('#select_server_dl').val(),
                            "select_server_ly": $('#select_server_ly').val(),
                            "select_server_yd": $('#select_server_yd').val(),
                            "select_server_ext": $('#select_server_ext').val(),

                            "pay_num_dl": $('#pay_num_dl').val(),
                            "pay_num_ext": $('#pay_num_ext').val(),

                            "recharge_dl": $('#recharge_dl').val(),
                            "recharge_ly": $('#recharge_ly').val(),
                            "recharge_yd": $('#recharge_yd').val(),
                            "recharge_ext": $('#recharge_ext').val(),


                            "online_dl": $('#online_dl').val(),
                            "online_ly": $('#online_ly').val(),
                            "online_ext": $('#online_ext').val(),

                            "create_role_dl": $('#create_role_dl').val(),
                            "create_role_ly": $('#create_role_ly').val(),
                            "create_role_yd": $('#create_role_yd').val(),
                            "create_role_ext": $('#create_role_ext').val(),

                            "level_dl": $('#level_dl').val(),
                            "level_ly": $('#level_ly').val(),
                            "level_ext": $('#level_ext').val(),

                            "recharge_switch_dl": $('#recharge_switch_dl').val(),
                            "recharge_switch_ext": $('#recharge_switch_ext').val(),

                            "assistance_dl": $('#assistance_dl').val(),
                            "assistance_ext": $('#assistance_ext').val(),

                            "change_account_dl": $('#change_account_dl').val(),
                            "change_account_ext": $('#change_account_ext').val(),

                            "share_dl": $('#share_dl').val(),
                            "share_ext": $('#share_ext').val(),

                            "update_dl": $('#update_dl').val(),
                            "update_ext": $('#update_ext').val(),

                            "pkg_name_dl": $('#pkg_name_dl').val(),
                            "pkg_name_ext": $('#pkg_name_ext').val(),

                            "message_dl": $('#message_dl').val(),
                            "message_ext": $('#message_ext').val(),

                            "gift_dl": $('#gift_dl').val(),
                            "gift_ly": $('#gift_ly').val(),
                            "gift_ext": $('#gift_ext').val(),

                            "define_yd": $('#define_yd').val(),
                            "define_ext": $('#define_ext').val(),

                            "test_ext": $('#test_ext').val()

                        },
                        dataType: 'json',
                        success: function (data) {
                            $('#game_detail').attr('disabled', 'disabled');
                            $('#test_ext').attr('disabled', 'disabled');
                            $('#apk').attr('disabled', 'disabled');
                            $('#log_id').val(data.log_id);
                            console.log("add_game_log:", data);
                        }
                    });
                    //日志停止
                    log_handdle(client_id, false);
                }
            }

        }

        <!-- 根据下拉选项pt_type的值来判断是否显示小助手 -->
        function change_pt_type() {
            e = $('#pt_type');
            var p1 = e.children('option:selected').val();
            if (p1 == "jm") {
                $('.sy').hide();
                $('select#assistance_dl').val("3");
                $('#assistance_ext').val("静默版不显示小助手");
            } else {
                $('.sy').show();
                //$('.sy').removeClass("hidden");
                $('select#assistance_dl').val("");
                $('#assistance_ext').val("");
            }

        }

        <!-- 获取SDK客户端报告 -->
        function get_sdk_report() {
            var client_id = $('#client').val();
            var url = "/pkg/sdk_report?gameId=" + client_id;
            window.open(url);

        }

        <!-- 删除确认框-->
        $('#confirm-delete').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var btn_ok = $(this).find('.btn-ok');
            var action = button.data('whatever');
            btn_ok.click(function () {
                eval(action)();
                $('#confirm-delete').modal('hide')

            });
        });

        <!-- 弹出邮件确认框 -->
        $('#emailModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var log_id = button.data('whatever');
            var client_id = $('#client').val();
            var modal = $(this);
            modal.find('.modal-title').text('邮件发送确认');
            if (client_id) {
                // 遍历input窗口，更新value值
                $("td input").each(function (a, b) {
                    var value = $(b).val();
                    $(b).attr('value', value);
                });
                // 遍历textarea窗口，更新内容
                $("textarea").each(function (a, b) {
                    var value = $(b).val();
                    $(b).text(value);
                });
                // 遍历select窗口，更新所选择的值。
                $("#case_content select").each(function (a, b) {
                    var value = $(b).val();
                    if (value) {
                        //更新select 选择项selected=true
                        $(b).find("option[value=" + value + "]").attr("selected", true);
                    }
                });
                // 提取原界面doc结构，用于后面的恢复
                var origin_html = $('#case_content').html();
                // 提取页面中的相关字段信息
                var game_name = $('#game_name').val();
                var game_type = $('#game_type').val();
                var appver = $('#appver').val();
                var pt_type = "4399sy";
                if ($('#pt_type').val() == "jm") {
                    var pt_type = "靜默版";
                }
                var recharge = $("#recharge option:selected").text();
                var result = $("#result option:selected").text();
                var today = new Date();
                var current_day = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate();
                var username = $('#username').text() + "|" + current_day;
                $('#modify_date').attr('value', username);
                $('#modify_date').val(username);
                html_title = "<h4>《<b>" + game_name + "</b>》" + game_type + "-V" + appver + " " + pt_type + " - " + recharge + " 版本更新接入SDK测试完成，测试结果为：<span style='color: red;font-size:30px'>" + result + "！</span> </h4>";
                var question = $("#test_ext").val();
                html_question = '<div style="width:100%;"><h4 style="margin-top: -20px">本次测试主要问题:</h4><pre style="font-size:18px;"><td colspan="6" id="test_ext" class="edit_log" style="height: auto;border: 1px solid black;word-break:break-all" value="">' + question + '</td></pre></div>';
                // 清洗邮件报告格式
                // 遍历input窗口，将input删除，只保留value
                $("td input").each(function (a, b) {
                    var value = $(b).val();
                    var p = $(b).parent();
                    var pp = p.parent();
                    if ($(p).is(":hidden") || $(pp).is(":hidden")) {
                    } else {
                        if ($(p).get(0).tagName == "DIV") {
                            p.remove();
                            pp.append("<span> : " + value + "</span>");
                        } else {
                            p.empty();
                            p.text(value);
                        }
                    }

                });
                // 遍历select窗口，将select删除，只保留所选择的值。
                $("#case_content select").each(function (a, b) {
                    var value = $(b).val();
                    var p = $(b).parent();
                    var pp = p.parent();
                    var content = "";
                    if (value) {
                        content = $(b).find("option[value=" + value + "]").text();
                    }
                    if ($(p).is(":hidden") || $(pp).is(":hidden")) {
                    } else {
                        if ($(p).get(0).tagName == "DIV") {
                            p.remove();
                            pp.append("<span> : " + content + "</span>");
                        } else {
                            p.empty();
                            p.text(content);
                        }
                    }

                });

                report_html = html_title + $('#game_detail').html() + html_question;
                // 将所有id去掉,避免页面中有重复的id值，导致控制台报错。
                report_html = report_html.replace(/id="(.*?)"/g, "");
                modal.find('.modal-body')[0].innerHTML = report_html;
                // 恢复页面
                $('#case_content').html(origin_html);
            } else {
                modal.find('.modal-body')[0].innerHTML = "client_id 为空，请检查是否已经选择了游戏！"
            }
        });

        <!-- 日志说明模态框-->
        $('#stepModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var step_id = button.data('whatever');
            var modal = $(this);
            modal.find('.modal-title').text('测试点:' + step_id);
            $.ajax({
                url: "{% url 'doc_file' %}",
                data: {'file_name': step_id},
                type: 'GET',
                dataType: 'html',
                success: function (data) {
                    modal.find('.modal-body')[0].innerHTML = data;
                }
            });

        });

        <!-- 日志处理函数 -->
        function log_handdle(client_id, is_open) {
            if (client_id) {
                // 取消定时器 轮询
                clearInterval(API_LOOP);
                if (is_open) {
                    // 开始轮询API报告
                    API_LOOP = setInterval(function () {
                        show_api_report(client_id);
                    }, 20000);

                }

            }
        }

        <!-- 创建新用户模式开关 -->
        function change_new_user(client_id, is_open) {
            if (client_id) {
                $.ajax({
                    url: "{% url 'new_user_setting' %}",
                    data: {
                        'client_id': client_id,
                        'is_open': is_open
                    },
                    type: 'GET',
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 1000) {
                            // 开启成功，将开关状态值设置为off
                            $('#new_user_setting').val("off");
                            $('#new_user').text("新玩家模式on");
                        } else {
                            // 关闭成功，将开关状态值设置为on
                            $('#new_user_setting').val("on");
                            $('#new_user').text("新玩家模式off");
                        }
                        console.log(data);

                    }
                });

            } else {
                alert("client_id参数有误");
            }

        }

        <!-- 版本号比较 1.4.4.0，1.4.4.9 false 比较第一个参数版本号是否大于第二个参数版本号-->
        function versionCompare(v1, v2) {
            var v1parts = v1.split('.');
            var v2parts = v2.split('.');
            while (v1parts.length < v2parts.length) v1parts.push("0");
            v1parts = v1parts.map(Number);
            v2parts = v2parts.map(Number);
            // versionCompare("1.4.4.9","1.4.4.9")
            for (var i = 0; i <= v1parts.length; ++i) {
                if (v2parts.length == i) {
                    return false;
                }
                if (v1parts[i] == v2parts[i]) {
                    continue;
                }
                else if (v1parts[i] > v2parts[i]) {
                    return true;
                }
                else {
                    return false;
                }
            }
        }

        <!-- sdk 参数校验-->
        var sdk_params = {
            preServerID: false,
            preUID: false,
            preLyUID: false,
            createNew: function () {
                var params = {};
                // 检查入参为空值或0
                params.verify = function (name, value, case_title) {
                    case_title = case_title || "";
                    if (value == "" || value == "0") {
                        alert(case_title + " 发送参数错误:" + name + "=" + value);
                    }
                    // 比较uid的正确性
                    if (name == "uid" && sdk_params.preUID) {
                        if (value != sdk_params.preUID) {
                            alert(case_title + " uid 参数有误:" + value + "不等于参照值:" + sdk_params.preUID);
                        }
                    }
                    // 比较联运uid的正确性
                    if (name == "ly_uid" && sdk_params.preLyUID) {
                        if (value != sdk_params.preLyUID) {
                            alert(case_title + " uid 参数有误:" + value + "不等于参照值:" + sdk_params.preLyUID);
                        }
                    }
                    // 比较serverId的正确性
                    if (name == "serverId" && sdk_params.preServerID) {
                        if (value != sdk_params.preServerID) {
                            alert(case_title + " serverId 参数有误:" + value + "不等于参照值:" + sdk_params.preServerID);
                        }
                    }
                };
                // 注册时，设置UID-参照值
                params.setPreUID = function (uid) {
                    sdk_params.preUID = uid;
                    console.log("-->>设置sy的uid参照值:" + uid);
                };
                // 注册时，设置联运UID-参照值
                params.setPreLyUID = function (uid) {
                    sdk_params.preLyUID = uid;
                    console.log("-->>设置联运的uid参照值:" + uid);
                };
                // 选服时，设置游戏服ID-参照值
                params.setPreServerID = function (serverid) {
                    console.log("-->>设置serverId参照值:" + serverid);
                    sdk_params.preServerID = serverid;
                };
                // 清除参照值,建议在打开app时清除
                params.clearPreValue = function () {
                    console.log("-->>新打开游戏，清除UID，ServerID参照值");
                    sdk_params.preServerID = false;
                    sdk_params.preLyUID = false;
                    sdk_params.preUID = false;
                };
                return params;
            }
        };

        <!-- 根据抓包日志，自动填充用例表格-->
        function auto_fill_log(data, yd_flag, client_id) {
            var check = sdk_params.createNew();
            if (yd_flag) { // 源点日志
                if (data.plat == "源点推送") {
                    // 源点包，默认sy包
                    $('select#pt_type').val("sy");

                    // 打开APP日志
                    if (data.action_type == "MuTBIhzZOrQLO0O0OBO0O0Om") {

                        // 填充sy_sdk
                        if ($('#sy_sdk').val() == "") {
                            $('#sy_sdk').val(data.data.sdkver);
                        }
                        // 填充设备号
                        $('#device_id').val(data.data.did);

                        // 填充打开APP日志
                        if ($('#open_game_yd').val() == "") {
                            $('#open_game_yd').val(1);
                        }

                        // 填充project_id
                        if (data.project_id) {
                            $('#project_id').val(data.project_id);
                            $.getJSON('{% url "get_yd_projectid" %}', {
                                    "game_id": client_id,
                                    "project_id": data.project_id
                                }, function (project_data) {
                                    //console.log(project_data);
                                    if (!project_data.flag) {
                                        //alert(JSON.stringify(project_data,undefined, 4));
                                        alert(project_data.msg);
                                    }

                                }
                            );
                        }

                        // IOS 填充appversion版本号
                        error_msg = "";
                        if ($('#appver').val() == "") {
                            // appversion 对比上一个版本
                            $.getJSON('{% url "last_version" %}', {"game_id": client_id}, function (vdata) {
                                if (versionCompare(data.data.appver, vdata.appver)) {
                                    console.log("当前版本：appVersion=" + data.data.appver + "\n上一版本：appVersion=" + vdata.appver);
                                } else {
                                    error_msg = "当前版本：appVersion=" + data.data.appver + "\n上一版本：appVersion=" + vdata.appver;
                                    error_msg += "\n请仔细核查！\n[对比条件:以一天前的测试记录为对比]";
                                    alert(error_msg);
                                }
                            });

                            $('#appver').val(data.data.appver);
                        }

                    }
                    //注册日志
                    else if (data.action_type == "MuTBIhzZOrALO0O0OBO0O0Om") {
                        // 注册时，设置uid参照值
                        check.setPreUID(data.data.uid);
                        if ($('#regist_yd').val() == "") {
                            $('#regist_yd').val(1);
                            $('#regist_yd_ext').val($('#regist_yd_ext').val().replace(/\[.*?\]/g, ">>") + "[uid=" + data.data.uid + "]");
                        }
                    }
                    //平台登陆日志
                    else if (data.action_type == "MuTBIh0ZMrALO0O0OBO0O0Om") {
                        // 校验uid
                        check.verify("uid", data.data.uid, "源点平台登陆日志:");
                        if ($('#login_yd').val() == "") {
                            $('#login_yd').val(1);
                            $('#login_ext').val($('#login_ext').val().replace(/\[.*?\]/g, ">>") + "[uid=" + data.data.uid + "]");
                        }
                    }
                    //选服日志
                    else if (data.action_type == "MuTBIh0ZMrQLO0O0OBO0O0Om") {
                        // 选服时，设置游戏服参照值
                        check.setPreServerID(data.data.server);
                        if ($('#select_server_yd').val() == "") {
                            $('#select_server_yd').val(1);
                            $('#select_server_ext').val($('#select_server_ext').val().replace(/\[.*?\]/g, ">>") + "[serverId=" + data.data.server + ";uid=" + data.data.uid + "]");
                        }
                    }
                    //创角日志
                    else if (data.action_type == "MuTBIh0ZMrgLO0O0OBO0O0Om") {
                        // 校验uid,游戏服
                        check.verify("uid", data.data.uid, "源点创角日志:");
                        check.verify("serverId", data.data.server, "源点创角日志:");

                        if ($('#create_role_yd').val() == "") {
                            $('#create_role_yd').val(1);
                            $('#create_role_ext').val($('#create_role_ext').val().replace(/\[.*?\]/g, ">>") + "[nickname=" + data.data.rolename + ";uid=" + data.data.uid + ";server=" + data.data.server + "]");
                        }
                    }
                    // 自定义事件
                    else if (data.action_type == "MuTBIh0ZNrgLO0O0OBO0O0Om") {
                        $('#define_ext').val($('#define_ext').val() + ">>" + data.data.eventname + "=" + data.data.eventvalue);
                        //console.log("自定义事件：" + data.data)
                    }
                    else {
                        console.log("未自定义事件：" + data.action_type)
                    }

                }
            } else {
                // 大陆联运日志
                if (data.plat == "大陆联运") {
                    // 大陆联运 打开日志
                    if (data.action_type == "activity_open") {
                        if ($('#fn_sdk').val() == "") {
                            $('#fn_sdk').val(data.data.sdkVersion);
                        }
                        if ($('#open_game_ly').val() == "") {
                            $('#open_game_ly').val(1);
                        }
                    }
                    // 大陆联运 登录界面前日志
                    if (data.action_type == "activity_before_login") {
                        if ($('#before_login_ly').val() == "") {
                            $('#before_login_ly').val(1);
                        }
                    }
                    // 大陆联运 选服日志
                    if (data.action_type == "user_server_login") {
                        if ($('#select_server_ly').val() == "") {
                            $('#select_server_ly').val(1);
                        }
                    }
                    // 大陆联运 创角日志
                    if (data.action_type == "user_create_role") {
                        if ($('#create_role_ly').val() == "") {
                            $('#create_role_ly').val(1);
                            $('#create_role_ext').val($('#create_role_ext').val().replace(/\[.*?\]/g, ">>") + "[nickname=" + data.data.roleName + ";uid=" + data.data.uid + ";serverId=" + data.data.serverId + "]");
                        }
                    }
                    // 大陆联运 在线日志
                    if (data.action_type == "user_online") {
                        if ($('#online_ly').val() == "") {
                            $('#online_ly').val(1);
                            if ($('#online_ext').val() == "") {
                                $('#online_ext').val("[uid=" + data.data.uid + ";serverId=" + data.data.serverId + "]");
                            }
                        }
                    }

                    // 大陆联运 等级日志
                    if (data.action_type == "role_level") {
                        if ($('#level_ly').val() == "") {
                            $('#level_ly').val(1);
                            $('#level_ext').val($('#level_ext').val().replace(/\[.*?\]/g, ">>") + "[roleLevel=" + data.data.roleLevel + ";uid=" + data.data.uid + ";serverId=" + data.data.serverId + "]");


                        }
                    }

                    // 大陆联运 礼包激活日志
                    if (data.action_type == "gift_code") {
                        if ($('#gift_ly').val() == "") {
                            $('#gift_ly').val(1);
                            $('#gift_ext').val($('#gift_ext').val().replace(/\[.*?\]/g, ">>") + "[giftCode=" + data.data.giftCode + ";uid=" + data.data.uid + "]");

                        }
                    }

                }

                // API 操作日志
                if (data.plat == "API操作") {
                    // 大陆SY 礼包激活日志
                    if (data.action_type == "giftcode") {
                        if ($('#gift_dl').val() == "") {
                            $('#gift_dl').val(1);
                        }
                    }
                    // API 注册账号/自动登录,更新uid参照值。
                    if (data.action_type == "reg" || data.action_type == "auto_login" || data.action_type == "login") {
                        if (data.response.result.uid) {
                            check.setPreUID(data.response.result.uid);
                        }
                    }
                    // API 临时账号登录分配,更新uid参照值。
                    if (data.action_type == "temp_login") {
                        check.setPreUID(data.response.suid);
                    }
                    // API 切换账号登录
                    if (data.action_type == "silence_login") {
                        check.setPreUID(data.data.suid);
                    }
                }

                // 大陆SY日志
                if (data.plat == "大陆SY") {
                    // 大陆SY日志 打开游戏日志
                    if (data.action_type == "open_game") {
                        // 清空对比值
                        check.clearPreValue();

                        // 填充sy_sdk
                        if ($('#sy_sdk').val() == "") {
                            $('#sy_sdk').val(data.data.open_game[0].sdkVersion);
                        }
                        // 填充设备号
                        $('#device_id').val(data.data.common.did);
                        if ($('#open_game_dl').val() == "") {
                            $('#open_game_dl').val(1);
                        }
                        // IOS 填充appversion版本号
                        error_msg = "";
                        if ($('#appver').val() == "") {
                            // appversion 对比上一个版本
                            var client_id = $("#client").val();
                            $.getJSON('{% url "last_version" %}', {"game_id": client_id}, function (vdata) {
                                if (versionCompare(data.data.open_game[0].appVersion, vdata.appver)) {
                                    console.log("当前版本：appVersion=" + data.data.open_game[0].appVersion + "\n上一版本：appVersion=" + vdata.appver);
                                } else {
                                    error_msg = "当前版本：appVersion=" + data.data.open_game[0].appVersion + "\n上一版本：appVersion=" + vdata.appver;
                                    error_msg += "\n请仔细核查！\n[对比条件:以一天前的测试记录为对比]";
                                    console.log(error_msg);
                                    alert(error_msg);
                                }
                            });
                            $('#appver').val(data.data.open_game[0].appVersion);
                        }


                        // 填充sychannel渠道号
                        if ($('#pkg_name_ext').val() == "") {
                            $('#pkg_name_ext').val("[channel_id=" + data.data.open_game[0].channelId + "]");
                        }

                        // IOS填充plat（sy,jm）
                        if ($('#pt_type').val() == "") {
                            if (data.data.common.sdk_type) {
                                if (data.data.common.sdk_type == "1") {
                                    $('select#pt_type').val("jm");
                                    $('.sy').hide();
                                    $('select#assistance_dl').val("3");
                                    $('#assistance_ext').val("静默版不显示小助手");
                                } else {
                                    $('select#pt_type').val("sy");
                                    $('.sy').show();
                                    $('select#assistance_dl').val("");
                                    $("select#assistance_dl").removeAttr("selected");
                                    $('#assistance_ext').val("");
                                    $('#assistance_ext').attr('value', "");
                                }
                            }
                        }
                    }

                    // 大陆SY日志 登录界面前
                    if (data.action_type == "open_login") {
                        if ($('#before_login_dl').val() == "") {
                            $('#before_login_dl').val(1);
                        }
                    }
                    // 大陆SY日志 选服日志
                    if (data.action_type == "select_server") {
                        // 选服时，更新游戏服参照值
                        check.setPreServerID(data.data.select_server[0].serverId);

                        if ($('#select_server_dl').val() == "") {
                            $('#select_server_dl').val(1);
                            $('#select_server_ext').val($('#select_server_ext').val().replace(/\[.*?\]/g, ">>") + "[serverId=" + data.data.select_server[0].serverId + ";uid=" + data.data.select_server[0].uid + "]");
                        }
                    }
                    // 大陆SY日志 在线日志
                    if ($('#online_dl').val() == "") {
                        // 升级，校验游戏服,uid
                        check.verify("serverId", data.data.online[0].serverId, "SY在线日志:");
                        check.verify("uid", data.data.online[0].uid, "SY在线日志:");
                        $('#online_dl').val(3);
                        $('#online_ext').val($('#online_ext').val().replace(/\[.*?\]/g, ">>") + "[uid=" + data.data.online[0].uid + ";serverId=" + data.data.online[0].serverId + "]");
                    }
                    // 大陆SY日志 创角日志
                    if (data.action_type == "create_role") {
                        // 创角，校验游戏服,uid
                        check.verify("serverId", data.data.create_role[0].serverId, "SY创角日志:");
                        check.verify("uid", data.data.create_role[0].uid, "SY创角日志:");
                        if ($('#create_role_dl').val() == "") {
                            $('#create_role_dl').val(1);
                            $('#create_role_ext').val($('#create_role_ext').val().replace(/\[.*?\]/g, ">>") + "[nickname=" + data.data.create_role[0].roleName + ";uid=" + data.data.create_role[0].uid + ";serverId=" + data.data.create_role[0].serverId + "]");
                        }
                    }
                    // 大陆SY日志 等级日志
                    if (data.action_type == "role_level_change") {
                        // 升级，校验游戏服,uid
                        check.verify("serverId", data.data.role_level_change[0].serverId, "SY等级日志:");
                        check.verify("uid", data.data.role_level_change[0].uid, "SY等级日志:");
                        if ($('#level_dl').val() == "") {
                            $('#level_dl').val(1);
                            $('#level_ext').val($('#level_ext').val().replace(/\[.*?\]/g, ">>") + "[roleLevel=" + data.data.role_level_change[0].roleLevel + ";uid=" + data.data.role_level_change[0].uid + ";serverId=" + data.data.role_level_change[0].serverId + "]");
                        }
                    }

                    // 大陆SY日志 礼包激活日志
                    if (data.action_type == "gift_code") {
                        if ($('#gift_dl').val() == "") {
                            $('#gift_dl').val(1);
                        }
                    }

                }

            }
        }

        <!-- socket 处理-->
        function socket_handler(client_id) {
            //var client_id = $(this).children('option:selected').val();
            if (window.s) {
                window.s.close() //关闭websocket
            }
            /*创建socket连接*/
            var socket = new WebSocket("ws://" + window.location.host + "/pkg/sub/");
            socket.onopen = function () {
                console.log('WebSocket open:', client_id);//成功连接上Websocket
                window.s.send(client_id);//通过websocket发送数据
            };
            socket.onmessage = function (e) {
                //console.log('[SDK]: ' + e.data);//打印出服务端返回过来的数据
                var data = JSON.parse(e.data);
                if (data.plat != "API操作") {
                    console.log(data.plat + ":" + data.action_name + "  上报时间：" + data.action_time);
                    console.log(data);
                    console.log("");
                }
                // 日志填充表格
                var yd_flag = false;
                if ($("#project_id").is(":visible")) {
                    yd_flag = true;
                }
                auto_fill_log(data, yd_flag, client_id);
            };
            // Call onopen directly if socket is already open
            if (socket.readyState == WebSocket.OPEN) socket.onopen();
            window.s = socket;
        }


    </script>



{% endblock %}